using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.Globalization;

using SoinusLibrary;

using LoginWebService;

public partial class _Register : System.Web.UI.Page
{
    #region Fields
    private LoginWS _loginWS;
    private ResourceManager _resourceMgr;
    private CultureInfo _ci; 
    #endregion

    #region Methods - Private
    private void initializeServices()
    {
        _loginWS = new LoginWS();
        _loginWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
    } 
    #endregion

    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        initializeServices();

        _resourceMgr = ResourceManager.CreateFileBasedResourceManager("Language", @"C:\inetpub\wwwroot\desarrollo\SoinusWeb\Languages", null);
        _ci = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);

        this.lblEmail.Text = _resourceMgr.GetString("lblEmail", _ci);
        this.lblPass.Text = _resourceMgr.GetString("lblPass", _ci);
        this.lblPassConfirm.Text = _resourceMgr.GetString("lblPassConfirm", _ci);
        this.btnRegister.Text = _resourceMgr.GetString("btnRegister", _ci);
    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        string email = tbxEmail.Text;
        string pass = tbxPass.Text;
        string passConfirm = tbxPassConfirm.Text;

        lblRegisterResult.Text = "";

        if (pass.Equals(passConfirm))
        {
            if (!_loginWS.UserExists(email))
            {
                if (_loginWS.RegisterUser(email, pass) == Message.OK)
                {
                }
                else
                {
                }
            }
            else
            {
                lblRegisterResult.Text = _resourceMgr.GetString("errorEmailExists", _ci);
            }
        }
        else
        {
            lblRegisterResult.Text = _resourceMgr.GetString("errorPassConfirm", _ci);
        }

        tbxPass.Text = "";
        tbxPassConfirm.Text = "";
    }
    #endregion
}
